package logic

import (
	"context"
	"encoding/json"

	"lottery-zero/internal/model"
	"lottery-zero/internal/svc"
	"lottery-zero/internal/types"

	"github.com/tal-tech/go-zero/core/logx"
	"gorm.io/gorm"
)

type SsqfreezeforeverbetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSsqfreezeforeverbetLogic(ctx context.Context, svcCtx *svc.ServiceContext) SsqfreezeforeverbetLogic {
	return SsqfreezeforeverbetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SsqfreezeforeverbetLogic) Ssqfreezeforeverbet(req types.SsqTicksFreezeForeverReq, userId string) (*types.CodeReply, error) {

	userInt, _ := json.Number(userId).Int64()
	db := l.svcCtx.PGDB.Model(&model.UserDoubleBallForever{}).Where(&model.UserDoubleBallForever{ID: uint(req.Id), UserID: uint(userInt)})
	var result *gorm.DB
	switch req.Mode {
	case 0:
		result = db.Update("Disabled", true)
	case 1:
		result = db.Update("Disabled", false)
	}

	return &types.CodeReply{Code: 200, Msg: "success"}, result.Error
}
